/*
 * EquipmentMissile.cpp
 *
 *  Created on: Jun 16, 2012
 *      Author: gonzalo
 */

#include "EquipmentMissile.h"
#include "../PlayScenarioPanel.h"

#define EQUIPMENTMISSILE_DEFAULT_QUANTITY 5
#define EQUIPMENTMISSILE_MAX_QUANTITY 5

EquipmentMissile::EquipmentMissile(Widget* parent): Equipment(MISSILE,parent)  {
	this->quantityLeft = EQUIPMENTMISSILE_DEFAULT_QUANTITY;
}

EquipmentMissile::EquipmentMissile(DTOEquipment* dtoEquipment,Widget* parent):
Equipment(dtoEquipment->bonusType, parent){
	this->quantityLeft = dtoEquipment->value;
}

void EquipmentMissile::handleEvent(Event event){
	EventType eventType = event.getType();

	//Translate EventType
	if (eventType == UserEvent) {
		if (event.getEvent()->user.code == UserKeyPressed) {
			eventType = KeyPressed;
		} else if (event.getEvent()->user.code == UserKeyReleased) {
			eventType = KeyReleased;
		}
	}

	if (this->quantityLeft > 0 && event.getKey()== Letter_M && eventType == KeyPressed){
		((PlayScenarioPanel*)parent)->addAmmo(AMMO_MISSILE);
		this->quantityLeft--;
	}
}

void EquipmentMissile::updateStatus(){
	if ( (quantityLeft + EQUIPMENTMISSILE_DEFAULT_QUANTITY) >
			EQUIPMENTMISSILE_MAX_QUANTITY)
		quantityLeft = EQUIPMENTMISSILE_MAX_QUANTITY;
	else
		quantityLeft += quantityLeft + EQUIPMENTMISSILE_DEFAULT_QUANTITY;
}

void EquipmentMissile::showOn(SDL_Surface* surface,int offsetX,int offsetY) {
	if(quantityLeft == 0){
		emptyFlag = true;
	}
}

DTOEquipment* EquipmentMissile::getDTO() {
	return new DTOEquipment(MISSILE,this->quantityLeft,((PlayScenarioPanel*)parent)->getOwner());
}

EquipmentMissile::~EquipmentMissile() {
}

